﻿using Microsoft.WindowsAzure.ServiceRuntime;
using Ninject;
using Nx.Azure.Web.Controllers;
using Nx.Bootstrappers;
using Nx.Cloud.Configuration;
using Nx.Kernel;

namespace Nx.Azure.Web
{
    public interface ITestInjectionService
    { }

    public class TestInjectionService : ITestInjectionService
    {
    }

    public class Bootstrapper : BootstrapperBase
    {
        protected override void ConfigureContainer()
        {
            // Register the CloudConfiguration singleton
            Kernel.Bind<ICloudConfiguration>()
                .ToConstant(CloudConfiguration.Instance)
                .InSingletonScope()
                .OnActivation((ctx, cc) =>
                {
                    cc.Initialize(() => RoleEnvironment.IsAvailable, () => RoleEnvironment.IsEmulated);
                });

            // Register types
            Kernel.RegisterTypeIfMissing<ITestInjectionService, TestInjectionService>(false);

            // Register controllers
            Kernel.RegisterTypeIfMissing<HomeController>(false);
            Kernel.RegisterTypeIfMissing<ValuesController>(false);
        }

        protected override IKernel CreateContainer()
        {
            return new StandardKernel();
        }
    }
}